var requireModules = [
    'angular',
    'ui-router',
    'controllers/registerController',
    'controllers/loginController',
    'directives/headerDirective',
];

require(requireModules, function (angular) {

    var App = angular.module('app', [
        'ui.router', //路由依赖
        'register', 'login' ,//自定义控制器的依赖
        'header'
    ]);

    App
    //路由配制
        .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
            $urlRouterProvider.otherwise('register');
            $stateProvider
                .state('register', {
                    url: '/register',
                    templateUrl: './src/views/register.html'
                })
                .state('login', {
                    url: '/login',
                    templateUrl: './src/views/login.html'
                });
        }])
        //http请求配制
        .config(function ($httpProvider) {
            $httpProvider.defaults.transformRequest = function (obj) {
                var str = [];
                for (var p in obj) {
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                }
                return str.join("&");
            };
            $httpProvider.defaults.headers.post = {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });

    return App;
});